<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>submit-valid文档 | 掏钱的机器猫</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/vue-admin-ui/assets/logo.png">
    <meta name="description" content="掏钱的机器猫的个人博客,记录随笔与学习笔记，个人项目等">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/vue-admin-ui/assets/css/0.styles.fb55c927.css" as="style"><link rel="preload" href="/vue-admin-ui/assets/js/app.21d1badc.js" as="script"><link rel="preload" href="/vue-admin-ui/assets/js/3.d02ddc64.js" as="script"><link rel="preload" href="/vue-admin-ui/assets/js/1.38c8ef5a.js" as="script"><link rel="preload" href="/vue-admin-ui/assets/js/23.42bfb2a3.js" as="script"><link rel="prefetch" href="/vue-admin-ui/assets/js/10.d9a14dc0.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/11.284df538.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/12.530bdb86.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/13.3dde5c1a.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/14.e18000c4.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/15.65b98979.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/16.953b2589.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/17.d6be13fa.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/18.a10ec5a3.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/19.f2ef083a.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/20.9e024a1a.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/21.b818c6cd.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/22.f3716a62.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/24.0382e6dc.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/25.9b1cf793.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/26.626abbca.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/27.d6b1a7e8.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/28.7381bce0.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/29.65b69672.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/30.70062600.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/31.036bec0e.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/32.1ec26c99.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/33.69485516.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/34.30a7370c.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/35.1e72f74a.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/36.a6aaafe3.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/4.984f5e20.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/5.2cbf0f84.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/6.eab8daa0.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/7.41bb2a3c.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/8.79ebffb7.js"><link rel="prefetch" href="/vue-admin-ui/assets/js/9.e9ae19e3.js">
    <link rel="stylesheet" href="/vue-admin-ui/assets/css/0.styles.fb55c927.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-2d5f533b><div data-v-2d5f533b><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-2d5f533b data-v-2d5f533b><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-64685f0e data-v-2d5f533b data-v-2d5f533b><h3 class="title" style="display:none;" data-v-64685f0e data-v-64685f0e>掏钱的机器猫</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-64685f0e data-v-64685f0e><input type="password" value="" data-v-64685f0e> <span data-v-64685f0e>Konck! Knock!</span> <button data-v-64685f0e>OK</button></label> <div class="footer" style="display:none;" data-v-64685f0e data-v-64685f0e><span data-v-64685f0e><i class="iconfont reco-theme" data-v-64685f0e></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-64685f0e>vuePress-theme-reco</a></span> <span data-v-64685f0e><i class="iconfont reco-copyright" data-v-64685f0e></i> <a data-v-64685f0e><span data-v-64685f0e>Ethan</span>
              
            <span data-v-64685f0e>2018 - </span>
            2022
          </a></span></div></div> <div class="hide" data-v-2d5f533b><header class="navbar" data-v-2d5f533b><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/vue-admin-ui/" class="home-link router-link-active"><img src="/vue-admin-ui/assets/logo.png" alt="掏钱的机器猫" class="logo"> <span class="site-name">掏钱的机器猫</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
        插件文档
      </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/vue-admin-ui-lib/" class="nav-link"><i class="iconfont undefined"></i>
    vue-admin-ui-lib
  </a></li><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/submit-valid/" aria-current="page" class="nav-link router-link-exact-active router-link-active"><i class="iconfont undefined"></i>
    submit-valid
  </a></li><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/open-utils/" class="nav-link"><i class="iconfont undefined"></i>
    open-utils
  </a></li></ul></div></div><div class="nav-item"><a href="/vue-admin-ui/handle/handle/method.html" class="nav-link"><i class="iconfont undefined"></i>
    手写代码
  </a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
        个人站点
      </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/ethan6" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
    Gitee
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://github.com/Ethan66" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
    Github
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <a href="https://github.com/Ethan66/vue-admin-ui" target="_blank" rel="noopener noreferrer" class="repo-link"><i class="iconfont reco-github"></i>
      Github
      <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask" data-v-2d5f533b></div> <aside class="sidebar" data-v-2d5f533b><div class="personal-info-wrapper" data-v-ca798c94 data-v-2d5f533b><img src="/vue-admin-ui/assets/logo.png" alt="author-avatar" class="personal-img" data-v-ca798c94> <h3 class="name" data-v-ca798c94>
    Ethan
  </h3> <div class="num" data-v-ca798c94><div data-v-ca798c94><h3 data-v-ca798c94>24</h3> <h6 data-v-ca798c94>文章</h6></div> <div data-v-ca798c94><h3 data-v-ca798c94>11</h3> <h6 data-v-ca798c94>标签</h6></div></div> <hr data-v-ca798c94></div> <nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-document"></i>
        插件文档
      </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/vue-admin-ui-lib/" class="nav-link"><i class="iconfont undefined"></i>
    vue-admin-ui-lib
  </a></li><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/submit-valid/" aria-current="page" class="nav-link router-link-exact-active router-link-active"><i class="iconfont undefined"></i>
    submit-valid
  </a></li><li class="dropdown-item"><!----> <a href="/vue-admin-ui/category/open-utils/" class="nav-link"><i class="iconfont undefined"></i>
    open-utils
  </a></li></ul></div></div><div class="nav-item"><a href="/vue-admin-ui/handle/handle/method.html" class="nav-link"><i class="iconfont undefined"></i>
    手写代码
  </a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
        个人站点
      </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/ethan6" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
    Gitee
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://github.com/Ethan66" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
    Github
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <a href="https://github.com/Ethan66/vue-admin-ui" target="_blank" rel="noopener noreferrer" class="repo-link"><i class="iconfont reco-github"></i>
      Github
      <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>submit-valid</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-admin-ui/category/submit-valid/" aria-current="page" class="active sidebar-link">submit-valid</a></li></ul></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-64685f0e data-v-2d5f533b><h3 class="title" style="display:none;" data-v-64685f0e data-v-64685f0e>submit-valid文档</h3> <!----> <label id="box" class="inputBox" style="display:none;" data-v-64685f0e data-v-64685f0e><input type="password" value="" data-v-64685f0e> <span data-v-64685f0e>Konck! Knock!</span> <button data-v-64685f0e>OK</button></label> <div class="footer" style="display:none;" data-v-64685f0e data-v-64685f0e><span data-v-64685f0e><i class="iconfont reco-theme" data-v-64685f0e></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-64685f0e>vuePress-theme-reco</a></span> <span data-v-64685f0e><i class="iconfont reco-copyright" data-v-64685f0e></i> <a data-v-64685f0e><span data-v-64685f0e>Ethan</span>
              
            <span data-v-64685f0e>2018 - </span>
            2022
          </a></span></div></div> <div data-v-2d5f533b><main class="page"><div class="page-title" style="display:none;"><h1 class="title">submit-valid文档</h1> <div data-v-3b7f5bdf><i class="iconfont reco-account" data-v-3b7f5bdf><span data-v-3b7f5bdf>Ethan</span></i> <i class="iconfont reco-date" data-v-3b7f5bdf><span data-v-3b7f5bdf>2020-10-23</span></i> <!----> <i class="iconfont reco-tag tags" data-v-3b7f5bdf><span class="tag-item" data-v-3b7f5bdf>submit-valid</span></i></div></div> <div class="theme-reco-content content__default" style="display:none;"><h1 id="submit-valid"><a href="#submit-valid" class="header-anchor">#</a> submit-valid</h1> <h2 id="引用库模块"><a href="#引用库模块" class="header-anchor">#</a> 引用库模块：</h2> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code>
<span class="token keyword">import</span> v <span class="token keyword">from</span> <span class="token string">'submit-valid'</span>
<span class="token comment">// judge：判断函数（支持基本类型和引用类型），返回true || false</span>
v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">&quot;dafb&quot;</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>str<span class="token punctuation">.</span><span class="token function">len</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// true</span>

<span class="token comment">// valid: 链式校验结果回调函数，通过then和catch处理校验后逻辑</span>
v<span class="token punctuation">.</span><span class="token function">valid</span><span class="token punctuation">(</span><span class="token string">&quot;dafb&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span>str<span class="token punctuation">.</span><span class="token function">len</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  <span class="token comment">// 输入校验正确后的逻辑</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'具体校验结果: '</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span>
  <span class="token comment">// 输入校验不正确后的逻辑</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment">// validate： 对象多个属性值同时校验结果回调函数，通过then和catch处理校验后逻辑</span>
v<span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token string">'string'</span><span class="token punctuation">,</span>
  <span class="token literal-property property">b</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token literal-property property">c</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token literal-property property">c1</span><span class="token operator">:</span> <span class="token string">'123'</span><span class="token punctuation">,</span> <span class="token literal-property property">c2</span><span class="token operator">:</span> <span class="token string">'4534'</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
    <span class="token literal-property property">a</span><span class="token operator">:</span> v<span class="token punctuation">.</span>str<span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token literal-property property">b</span><span class="token operator">:</span> v<span class="token punctuation">.</span>arr<span class="token punctuation">.</span><span class="token function">len</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token literal-property property">c</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token literal-property property">c1</span><span class="token operator">:</span> v<span class="token punctuation">.</span>str<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token literal-property property">c2</span><span class="token operator">:</span> v<span class="token punctuation">.</span>str
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  <span class="token comment">// 输入校验正确后的逻辑</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'具体校验结果: '</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span>
  <span class="token comment">// 输入校验不正确后的逻辑</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br></div></div><hr> <h2 id="方法说明"><a href="#方法说明" class="header-anchor">#</a> 方法说明</h2> <h2 id="类型校验"><a href="#类型校验" class="header-anchor">#</a> 类型校验</h2> <ul><li>.str  字符串验证链式对象。</li> <li>.num  数字验证链式对象。</li> <li>.obj  对象值类型验证链式对象。</li> <li>.arr  数组值验证链式对象。</li> <li>.boolean  布尔值验证链式对象。</li> <li>.any  任意类型数据验证链式对象。</li></ul> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token comment">// 类型校验</span>
<span class="token keyword">const</span> str <span class="token operator">=</span> <span class="token string">'str'</span><span class="token punctuation">,</span> num <span class="token operator">=</span> <span class="token number">123</span><span class="token punctuation">,</span> ob <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">,</span> arrs <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> bo <span class="token operator">=</span> <span class="token boolean">false</span>
<span class="token keyword">function</span> <span class="token function">valid</span> <span class="token punctuation">(</span><span class="token parameter">arg</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> str <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span>arg<span class="token punctuation">,</span> v<span class="token punctuation">.</span>str<span class="token punctuation">)</span>
  <span class="token keyword">const</span> num <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span>arg<span class="token punctuation">,</span> v<span class="token punctuation">.</span>num<span class="token punctuation">)</span>
  <span class="token keyword">const</span> ob <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span>arg<span class="token punctuation">,</span> v<span class="token punctuation">.</span>obj<span class="token punctuation">)</span>
  <span class="token keyword">const</span> arr <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span>arg<span class="token punctuation">,</span> v<span class="token punctuation">.</span>arr<span class="token punctuation">)</span>
  <span class="token keyword">const</span> bo <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span>arg<span class="token punctuation">,</span> v<span class="token punctuation">.</span>boolean<span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'-----my argument is %o, str is %o, num is %o, ob is %o, arr is %o, boolean is %o'</span><span class="token punctuation">,</span> arg<span class="token punctuation">,</span> str<span class="token punctuation">,</span> num<span class="token punctuation">,</span> ob<span class="token punctuation">,</span> arr<span class="token punctuation">,</span> bo<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">valid</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span>
<span class="token function">valid</span><span class="token punctuation">(</span>num<span class="token punctuation">)</span>
<span class="token function">valid</span><span class="token punctuation">(</span>ob<span class="token punctuation">)</span>
<span class="token function">valid</span><span class="token punctuation">(</span>arrs<span class="token punctuation">)</span>
<span class="token function">valid</span><span class="token punctuation">(</span>bo<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h2 id="范围校验"><a href="#范围校验" class="header-anchor">#</a> 范围校验</h2> <ul><li>.eq 等于。argument: any</li> <li>.not 不等于。argument: any</li> <li>.gt  大于。value, argument: string | number | Date</li> <li>.gte  大于等于。value, argument: string | number | Date</li> <li>.lt  小于。value, argument: string | number | Date</li> <li>.lte  小于等于。value, argument: string | number | Date</li> <li>.between 范围。value, arguments: string | number | Date</li> <li>.len  长度校验。value: string | number | any[], argument: string | number</li></ul> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token comment">// .eq</span>
<span class="token keyword">function</span> <span class="token function">eq</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> eq1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">eq</span><span class="token punctuation">(</span><span class="token number">123</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> eq2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">eq</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> eq3 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">eq</span><span class="token punctuation">(</span><span class="token number">345</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> eq4 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">eq</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> eq5 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">eq</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> eq6 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">eq</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is eq1 is %o, eq2 is %o, eq3 is %o, eq4 is %o, eq5 is %o, eq6 is %o'</span><span class="token punctuation">,</span> eq1<span class="token punctuation">,</span> eq2<span class="token punctuation">,</span> eq3<span class="token punctuation">,</span> eq4<span class="token punctuation">,</span> eq5<span class="token punctuation">,</span> eq6<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">eq</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment">// .not</span>
<span class="token keyword">function</span> <span class="token function">not</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> not1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">not</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> not2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">not</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> not3 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">not</span><span class="token punctuation">(</span><span class="token number">123</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> not4 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">not</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> not5 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">not</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> not6 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">not</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is not1 is %o, not2 is %o, not3 is %o, not4 is %o, not5 is %o, not6 is %o'</span><span class="token punctuation">,</span> not1<span class="token punctuation">,</span> not2<span class="token punctuation">,</span> not3<span class="token punctuation">,</span> not4<span class="token punctuation">,</span> not5<span class="token punctuation">,</span> not6<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">not</span><span class="token punctuation">(</span><span class="token punctuation">)</span>


<span class="token comment">// .gt, .gte, .lt, .lte</span>
<span class="token keyword">function</span> <span class="token function">gt</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> gt1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token string">'100'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> gt2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> gt3 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token number">300</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> gt4 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> gt5 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is gt1 is %o, gt2 is %o, gt3 is %o, gt4 is %o, gt5 is %o'</span><span class="token punctuation">,</span> gt1<span class="token punctuation">,</span> gt2<span class="token punctuation">,</span> gt3<span class="token punctuation">,</span> gt4<span class="token punctuation">,</span> gt5<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">gt</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment">// .between</span>
<span class="token keyword">function</span> <span class="token function">between</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> between1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">between</span><span class="token punctuation">(</span><span class="token string">'100'</span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> between2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">between</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token string">'250'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> between3 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">between</span><span class="token punctuation">(</span><span class="token number">300</span><span class="token punctuation">,</span> <span class="token string">'400'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is between1 is %o, between2 is %o, between3 is %o'</span><span class="token punctuation">,</span> between1<span class="token punctuation">,</span> between2<span class="token punctuation">,</span> between3<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">between</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br></div></div><h2 id="长度校验"><a href="#长度校验" class="header-anchor">#</a> 长度校验</h2> <ul><li>.len  相等。value: string | number | any[], argument: string | number</li> <li>.min  小于。value: string | number | any[], argument: string | number</li> <li>.max  大于。value: string | number | any[], argument: string | number</li></ul> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token comment">// .len</span>
<span class="token keyword">function</span> <span class="token function">len</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> len1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">len</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> len2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">len</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is len1 is %o, len2 is %o'</span><span class="token punctuation">,</span> len1<span class="token punctuation">,</span> len2<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">len</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment">// .min</span>
<span class="token keyword">function</span> <span class="token function">min</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> min1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> min2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is min1 is %o, min2 is %o'</span><span class="token punctuation">,</span> min1<span class="token punctuation">,</span> min2<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">min</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment">// .max</span>
<span class="token keyword">function</span> <span class="token function">max</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> max1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">max</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> max2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">max</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is max1 is %o, max2 is %o'</span><span class="token punctuation">,</span> max1<span class="token punctuation">,</span> max2<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">max</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h2 id="包含"><a href="#包含" class="header-anchor">#</a> 包含</h2> <ul><li>.has。value: string | number| any[] | object, arg: string | number| any</li></ul> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">has</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> has1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">has</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> has2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">has</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> has3 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">has</span><span class="token punctuation">(</span><span class="token string">'a'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is has1 is %o, has2 is %o, has3 is %o'</span><span class="token punctuation">,</span> has1<span class="token punctuation">,</span> has2<span class="token punctuation">,</span> has3<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">has</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="文件名"><a href="#文件名" class="header-anchor">#</a> 文件名</h2> <ul><li>.ext: value: string, arg: string</li></ul> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">ext</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> ext1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123.png'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">ext</span><span class="token punctuation">(</span><span class="token string">'png'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> ext2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'sdfs.txt'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">ext</span><span class="token punctuation">(</span><span class="token string">'txt'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> ext3 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'sdfs.txt'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">ext</span><span class="token punctuation">(</span><span class="token string">'png'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is ext1 is %o, ext2 is %o, ext3 is %o'</span><span class="token punctuation">,</span> ext1<span class="token punctuation">,</span> ext2<span class="token punctuation">,</span> ext3<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">ext</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="正则"><a href="#正则" class="header-anchor">#</a> 正则</h2> <ul><li>.reg: any, arg: RegExp</li></ul> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">reg</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> reg1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'123'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">reg</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">\d</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> reg2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">reg</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">\d</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> reg3 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span><span class="token function">reg</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">\d</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is reg1 is %o, reg2 is %o, reg3 is %o'</span><span class="token punctuation">,</span> reg1<span class="token punctuation">,</span> reg2<span class="token punctuation">,</span> reg3<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">reg</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="内置正则"><a href="#内置正则" class="header-anchor">#</a> 内置正则</h2> <ul><li>required: 必传,</li> <li>english: 英文,</li> <li>alphanum: 英文+数字,</li> <li>chinese: 中文,</li> <li>nospace: 不含任何空格字符,</li> <li>float: 浮点型,</li> <li>positivefloat: 正浮点型,</li> <li>integer: 整数,</li> <li>positiveint: 正整数,</li> <li>decimal: 小数,</li> <li>percent: 百分数,</li> <li>email: email,</li> <li>http: http地址,</li> <li>phone: 手机号,</li> <li>year: 年份,</li> <li>month: 月份,</li> <li>day: 日,</li> <li>hour: 0-23数字,</li> <li>minute: 0-59数字,</li> <li>hmt: 时分,</li> <li>time: 时分秒,</li> <li>date: 日期2020/10/10</li> <li>datetime: 日期时间 2020-10-11 20:20:12</li> <li>path: 路径,</li> <li>file: 文件名,</li> <li>imgurl: 图片地址</li></ul> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">reg2</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> reg1 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'https://www.baidu.com/123.png'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>str<span class="token punctuation">.</span>imgurl<span class="token punctuation">)</span>
  <span class="token keyword">const</span> reg2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'2020-10-10'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>str<span class="token punctuation">.</span>date<span class="token punctuation">)</span>
  <span class="token keyword">const</span> reg3 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span><span class="token string">'2000-05-02 20:08:10'</span><span class="token punctuation">,</span> v<span class="token punctuation">.</span>str<span class="token punctuation">.</span>datetime<span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is reg1 is %o, reg2 is %o, reg3 is %o'</span><span class="token punctuation">,</span> reg1<span class="token punctuation">,</span> reg2<span class="token punctuation">,</span> reg3<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">reg2</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="链式调用"><a href="#链式调用" class="header-anchor">#</a> 链式调用</h2> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">name</span> <span class="token punctuation">(</span><span class="token parameter">n</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> rules <span class="token operator">=</span> <span class="token punctuation">{</span>
    <span class="token literal-property property">username</span><span class="token operator">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span><span class="token literal-property property">required</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token literal-property property">message</span><span class="token operator">:</span> <span class="token string">'用户名不能为空'</span><span class="token punctuation">,</span> <span class="token literal-property property">trigger</span><span class="token operator">:</span> <span class="token string">'blur'</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span><span class="token literal-property property">type</span><span class="token operator">:</span> <span class="token string">'string'</span><span class="token punctuation">,</span> <span class="token literal-property property">message</span><span class="token operator">:</span> <span class="token string">'用户名必须为字符串'</span><span class="token punctuation">,</span> <span class="token literal-property property">trigger</span><span class="token operator">:</span> <span class="token string">'blur'</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span><span class="token literal-property property">min</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span>  <span class="token literal-property property">message</span><span class="token operator">:</span> <span class="token string">'用户名长度必须为大于2'</span><span class="token punctuation">,</span> <span class="token literal-property property">trigger</span><span class="token operator">:</span> <span class="token string">'blur'</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span><span class="token literal-property property">pattern</span><span class="token operator">:</span> <span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^[A-Za-z]+[\w\-_]*[A-Za-z0-9]+$</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">,</span> <span class="token literal-property property">message</span><span class="token operator">:</span> <span class="token string">'用户名必需字母或数字组合'</span><span class="token punctuation">,</span> <span class="token literal-property property">trigger</span><span class="token operator">:</span> <span class="token string">'blur'</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">]</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">const</span> name2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span>n<span class="token punctuation">,</span> v<span class="token punctuation">.</span>str<span class="token punctuation">.</span>required<span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">.</span>alphanum<span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is name: '</span><span class="token punctuation">,</span> name2<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">name</span><span class="token punctuation">(</span><span class="token string">'1s'</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="对象链式调用"><a href="#对象链式调用" class="header-anchor">#</a> 对象链式调用</h2> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">name2</span> <span class="token punctuation">(</span><span class="token parameter">n</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> name2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span>n<span class="token punctuation">,</span> <span class="token punctuation">{</span>
    <span class="token literal-property property">a</span><span class="token operator">:</span> v<span class="token punctuation">.</span>str<span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token literal-property property">b</span><span class="token operator">:</span> v<span class="token punctuation">.</span>arr<span class="token punctuation">.</span><span class="token function">len</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token literal-property property">c</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token literal-property property">c1</span><span class="token operator">:</span> v<span class="token punctuation">.</span>num<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token literal-property property">c2</span><span class="token operator">:</span> v<span class="token punctuation">.</span>str
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is name2: '</span><span class="token punctuation">,</span> name2<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">name2</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token string">'string'</span><span class="token punctuation">,</span>
  <span class="token literal-property property">b</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token literal-property property">c</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token literal-property property">c1</span><span class="token operator">:</span> <span class="token number">123</span><span class="token punctuation">,</span> <span class="token literal-property property">c2</span><span class="token operator">:</span> <span class="token string">'4534'</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="对象的单项链式调用"><a href="#对象的单项链式调用" class="header-anchor">#</a> 对象的单项链式调用</h2> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">name3</span> <span class="token punctuation">(</span><span class="token parameter">n</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> val <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>n<span class="token punctuation">,</span> <span class="token string">'c.c1'</span><span class="token punctuation">)</span>
  <span class="token keyword">const</span> name2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span>val<span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token literal-property property">c1</span><span class="token operator">:</span> v<span class="token punctuation">.</span>num<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token literal-property property">c2</span><span class="token operator">:</span> v<span class="token punctuation">.</span>str <span class="token punctuation">}</span><span class="token punctuation">)</span>
  console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is name3: '</span><span class="token punctuation">,</span> name2<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">name3</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token string">'string'</span><span class="token punctuation">,</span>
  <span class="token literal-property property">b</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token literal-property property">c</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token literal-property property">c1</span><span class="token operator">:</span> <span class="token number">123</span><span class="token punctuation">,</span> <span class="token literal-property property">c2</span><span class="token operator">:</span> <span class="token string">'4534'</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h2 id="验证结果逻辑处理"><a href="#验证结果逻辑处理" class="header-anchor">#</a> 验证结果逻辑处理</h2> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">line</span> <span class="token punctuation">(</span><span class="token parameter">n</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> name2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">valid</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">.</span>str<span class="token punctuation">.</span>required<span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">.</span>alphanum<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is res: '</span><span class="token punctuation">,</span> res<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is e: '</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">line</span><span class="token punctuation">(</span><span class="token string">'sdf'</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="对象验证结果逻辑处理"><a href="#对象验证结果逻辑处理" class="header-anchor">#</a> 对象验证结果逻辑处理</h2> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">object</span> <span class="token punctuation">(</span><span class="token parameter">n</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> name2 <span class="token operator">=</span> v<span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span>n<span class="token punctuation">,</span> <span class="token punctuation">{</span>
    <span class="token literal-property property">a</span><span class="token operator">:</span> v<span class="token punctuation">.</span>str<span class="token punctuation">.</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token literal-property property">b</span><span class="token operator">:</span> v<span class="token punctuation">.</span>arr<span class="token punctuation">.</span><span class="token function">len</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token literal-property property">c</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token literal-property property">c1</span><span class="token operator">:</span> v<span class="token punctuation">.</span>num<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token literal-property property">c2</span><span class="token operator">:</span> v<span class="token punctuation">.</span>str
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is success: '</span><span class="token punctuation">,</span> res<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is name2: '</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">object</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token literal-property property">a</span><span class="token operator">:</span> <span class="token string">'string'</span><span class="token punctuation">,</span>
  <span class="token literal-property property">b</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token literal-property property">c</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token literal-property property">c1</span><span class="token operator">:</span> <span class="token string">'123'</span><span class="token punctuation">,</span> <span class="token literal-property property">c2</span><span class="token operator">:</span> <span class="token string">'4534'</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><h2 id="message处理"><a href="#message处理" class="header-anchor">#</a> message处理</h2> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">msg</span> <span class="token punctuation">(</span><span class="token parameter">n</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  v<span class="token punctuation">.</span><span class="token function">valid</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">.</span>any<span class="token punctuation">.</span>required<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token number">18</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">lt</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">alias</span><span class="token punctuation">(</span><span class="token string">'年龄'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is res: '</span><span class="token punctuation">,</span> res<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is e: '</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>


  v<span class="token punctuation">.</span><span class="token function">valid</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">.</span>any<span class="token punctuation">.</span>required<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token number">18</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">lt</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">msg</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    <span class="token string-property property">'gt'</span><span class="token operator">:</span> <span class="token string">'我的年龄必须大于十八'</span><span class="token punctuation">,</span>
    <span class="token string-property property">'lt'</span><span class="token operator">:</span> <span class="token string">'我的年龄必须大于三十'</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is res: '</span><span class="token punctuation">,</span> res<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is e: '</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>


  v<span class="token punctuation">.</span><span class="token function">valid</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">.</span>any<span class="token punctuation">.</span>required<span class="token punctuation">.</span><span class="token function">gt</span><span class="token punctuation">(</span><span class="token number">18</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">lt</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">alias</span><span class="token punctuation">(</span><span class="token string">'年龄'</span><span class="token punctuation">,</span> <span class="token string">'十八'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is res: '</span><span class="token punctuation">,</span> res<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is e: '</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>

  v<span class="token punctuation">.</span><span class="token function">valid</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">.</span>num<span class="token punctuation">.</span><span class="token function">between</span><span class="token punctuation">(</span><span class="token number">18</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">msg</span><span class="token punctuation">(</span><span class="token string">'between'</span><span class="token punctuation">,</span> <span class="token string">'$name不仅要大于$arg1，也要小于$arg2！'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is res: '</span><span class="token punctuation">,</span> res<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is e: '</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">msg</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br></div></div><h2 id="自定义校验"><a href="#自定义校验" class="header-anchor">#</a> 自定义校验</h2> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">define</span> <span class="token punctuation">(</span><span class="token parameter">n</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  v<span class="token punctuation">.</span><span class="token function">valid</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">.</span>any<span class="token punctuation">.</span>num<span class="token punctuation">.</span><span class="token function">define</span><span class="token punctuation">(</span><span class="token parameter">r</span> <span class="token operator">=&gt;</span> r<span class="token operator">&gt;</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is res: '</span><span class="token punctuation">,</span> res<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is e: '</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">define</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">123</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="异步校验"><a href="#异步校验" class="header-anchor">#</a> 异步校验</h2> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token keyword">async</span> <span class="token punctuation">(</span><span class="token parameter">n</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  v<span class="token punctuation">.</span><span class="token function">judge</span><span class="token punctuation">(</span>n<span class="token punctuation">,</span> v<span class="token punctuation">.</span>any<span class="token punctuation">.</span>str<span class="token punctuation">.</span><span class="token function">async</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">res<span class="token punctuation">,</span> rej</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        <span class="token function">res</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is res: '</span><span class="token punctuation">,</span> res<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'----- my data is e: '</span><span class="token punctuation">,</span> e<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token keyword">async</span><span class="token punctuation">(</span><span class="token number">123</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div></div> <footer class="page-edit" style="display:none;"><!----> <div class="last-updated"><span class="prefix">上次更新: </span> <span class="time">2022/7/13 下午5:09:03</span></div></footer> <!----> <!----> <!----></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/vue-admin-ui/assets/js/app.21d1badc.js" defer></script><script src="/vue-admin-ui/assets/js/3.d02ddc64.js" defer></script><script src="/vue-admin-ui/assets/js/1.38c8ef5a.js" defer></script><script src="/vue-admin-ui/assets/js/23.42bfb2a3.js" defer></script>
  </body>
</html>
